/***************************************************************************
 *  Filename: maincontroller.h
 *  Class: MainController
 *  
 *  Copyright 2012  Mario Henrique Voorsluys
 *  <forcaeluz@gmail.com>
 *  
 ****************************************************************************/


#ifndef MAINCONTROLLER_H
#define MAINCONTROLLER_HtT

#include <QObject>
#include <QTimer>
#include <QMutex>

#define PropPitch   1
#define DiffPitch   1
#define DiffVelx    1

#define PropRoll    1
#define DiffRoll    1
#define DiffVely    1

#define PropGaz     1
#define DiffGaz     1

#define PropYaw     1

#define MaxRoll     15.0
#define MaxPitch    15.0
#define MaxYaw      15.0
#define MaxGaz      2.0
class MainController : public QObject
{
    Q_OBJECT
public:
    explicit MainController(bool gps = false, QObject *parent=0);
    
signals:
    void updateCommands(float troll, float tpich, float tyaw, float tgaz);

public slots:
    void updateAnglesData(float troll, float tpitch, float tyaw);
    void updateSpeeds(float vxt, float vyt, float vzt, float yawrate);
    void updatePosition(float xt, float yt, float zt);
    void updateRelativeTarget(float xt, float yt, float zt, float yawt);

    void updateGpsInformation(float latitude, float longitude, float altitude, float bearing);
    void updateGpsTarget(float latitude, float longitude, float altitude, float bearing);

    void controlLoop();

private:
    float roll;
    float pitch;
    float yaw;

    float targetX;
    float targetY;
    float targetZ;
    float targetYaw;

    float x;
    float y;
    float z;

    float vx;
    float vy;
    float vz;
    float yawRate;

    float latitude;
    float longitude;
    //Responsible for starting a new control-loop calculation every 10 ms.
    QTimer timer;
    //Protects data in multithreading environment.
    QMutex mutex;
    bool gpsMode;
};

#endif // MAINCONTROLLER_H
